<?php
/**
 * Created by PhpStorm.
 * User: xiaoxin
 * Date: 2018/11/13 0013
 * Time: 14:10
 */

namespace app\admin\controller;
use think\Controller;
use app\index\model\User;
use think\Db;

class Del extends Common
{
	/**
	 * 删除用户主页
	 * @return mixed
	 * @throws \think\exception\DbException
	 */
	public function userDel(){
		$where = [];
		input('nickname') && $where['nickname'] = ['like','%'.input('nickname').'%'];
		$user = Db::name('user')->where('delete_time','not null')->where($where)->paginate(5);
		$this->assign('users',$user);
		return $this->fetch();
	}


	/**
	 * 彻底删除用户方法
	 */
	public function delTrue(){
		$userId = input('post.');
		$res = User::destroy($userId,true);
		if ($res){
			$this->success('已删除');
		}else{
			$this->error('删除失败，请稍后再试');
		}
	}


	/**
	 * 恢复用户方法
	 * @throws \think\Exception
	 * @throws \think\exception\PDOException
	 */
	public function recover(){
		$userId = input('post.');
		$res = Db::name('user')->where('user_id', $userId['user_id'])
			->update(['delete_time' => null,'static'=>'0']);
		if ($res){
			$this->success('已恢复');
		}else{
			$this->error('恢复失败，请稍后再试');
		}
	}


	public function recoverAll(){
		$userId = input('post.');
		$res = Db::name('user')->where('user_id','in', $userId['user_id'])
			->update(['delete_time' => null,'static'=>'0']);
		if ($res){
			$this->success('已恢复');
		}else{
			$this->error('恢复失败，请稍后再试');
		}
	}
}